package cn.signalpha.modules.shop.service;

import cn.signalpha.core.tool.utils.BeanUtil;
import cn.signalpha.core.tool.utils.ObjectUtil;
import cn.signalpha.modules.shop.entity.GoodsBrand;
import cn.signalpha.modules.shop.excel.GoodsBrandExcel;
import cn.signalpha.modules.shop.mapper.GoodsBrandMapper;
import cn.signalpha.modules.shop.vo.GoodsBrandVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 服务类
 *
 * @author signalpha
 */
@Service
public class GoodsBrandService extends ServiceImpl<GoodsBrandMapper, GoodsBrand> {

	/**
	 * 自定义分页
	 */
    public IPage<GoodsBrandVO> selectGoodsBrandPage(IPage<GoodsBrandVO> page, Map<String, Object> params) {
        return page.setRecords(baseMapper.selectGoodsBrandPage(page, params));
    }

    /**
	 * 自定义导出
	 */
    public List<GoodsBrandExcel> selectGoodsBrandExcel(Map<String, Object> params) {
        return BeanUtil.copy(baseMapper.selectGoodsBrandPage(null, params), GoodsBrandExcel.class);
    }

    /**
	 * 自定义Wrappers
	 */
    public QueryWrapper<GoodsBrand> selectGoodsBrandWrapper(Map<String, Object> params) {
        QueryWrapper<GoodsBrand> wrapper = Wrappers.query();
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("id")), GoodsBrand::getId, params.get("id"));
        wrapper.lambda().like(ObjectUtil.isNotEmpty(params.get("name")), GoodsBrand::getName, params.get("name"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("status")), GoodsBrand::getStatus, params.get("status"));
        wrapper.lambda().like(ObjectUtil.isNotEmpty(params.get("categoryId")), GoodsBrand::getCategoryId, params.get("categoryId"));
        wrapper.lambda().orderByDesc(GoodsBrand::getSort).orderByDesc(GoodsBrand::getId);
        return wrapper;
    }

}

